package me.ydq.mapper;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 为 dynamic-query 提供默认的 RowMapper
 */
public class DefaultRowMapperProvider implements RowMapperProvider {

    static final Map<Class<?>, RowMapper<?>> ROW_MAPPER_CACHE = new ConcurrentHashMap<>();

    @Override
    public <T> RowMapper<T> build(Class<T> cls) {
        //noinspection unchecked
        return (RowMapper<T>) ROW_MAPPER_CACHE.computeIfAbsent(cls, BeanPropertyRowMapper::new);
    }
}
